// Generator函数

function* fn() {
  console.log(123);
  return 100;
}

// 跟普通函数不一样，这儿返回的是一个generator对象
const f = fn();

console.log(f);

console.log(f.next());

function* fn1() {
  console.log('111');
  yield 100;
  console.log('222');
  yield 200;
  console.log('333');
  yield 300;
}

const f1 = fn1();
// 惰性
console.log(f1.next());
console.log(f1.next());
console.log(f1.next());
console.log(f1.next());

const todos = {
  life: ['LOL', 'Music'],
  work: ['Front-end engineer'],
  skills: ['JavaScript', 'Python'],
  [Symbol.iterator]: function* () {
    const all = [...this.life, ...this.work, ...this.skills];
    for (const item of all) {
      yield item;
    }
  },
};

for (const item of todos) {
  console.log(item);
}
